﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyCommerce.Business.Stores;

namespace MyCommerce.Presentation.Stores.Presenters
{
    public class ProductStockTransferPresenter
    {
        private IViews.IProductStockTransfer vManagedView;

        public ProductStockTransferPresenter(IViews.IProductStockTransfer managedView)
        {
            if (managedView == null)
            {
                throw new Exception("managedView cannot be null");
            }

            vManagedView = managedView;
            vManagedView.OnLoad += new EventHandler(vManagedView_OnLoad);
            vManagedView.OnSave += new IViews.OnSaveEventHandler(vManagedView_OnSave);
            vManagedView.OnChangeOrigen += new Innova.FoundationFramework.DataTypes.GenericEventHandler<long>(vManagedView_OnChangeOrigen);
            vManagedView.OnChangeDestiny += new Innova.FoundationFramework.DataTypes.GenericEventHandler<long>(vManagedView_OnChangeDestiny);
        }

        void vManagedView_OnChangeDestiny(object sender, Innova.FoundationFramework.DataTypes.GenericEventArgs<long> e)
        {
            ProductStockManager vProductStockManager = new ProductStockManager();
            vManagedView.colProductStockDestiny = vProductStockManager.GetProductStockByIdStore(e.EventData);
        }

        void vManagedView_OnChangeOrigen(object sender, Innova.FoundationFramework.DataTypes.GenericEventArgs<long> e)
        {
            ProductStockManager vProductStockManager = new ProductStockManager();
            vManagedView.colProductStockOrigen = vProductStockManager.GetProductStockByIdStore(e.EventData);   
        }

        void vManagedView_OnSave(object sender, bool isNew)
        {
            ProductStockManager vProductStockManager = new ProductStockManager();
        }

        void vManagedView_OnLoad(object sender, EventArgs e)
        {
            ProductManager vProductManager = new ProductManager();
            vManagedView.colProduct = vProductManager.GetProducts();

            StoreManager vStoreManager = new StoreManager();
            vManagedView.colStoreOrigen = vStoreManager.GetStoresActives();
            vManagedView.colStoreDestiny = vStoreManager.GetStoresActives();
        }
    }
}
